<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="作物名称" prop="cropName">
        <el-input
          v-model="queryParams.cropName"
          placeholder="请输入农作物名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="作物类型" prop="cropName">
        <el-select v-model="queryParams.cropType" placeholder="请选择">
          <el-option
            v-for="item in cropType"
            :key="item.dictCode"
            :label="item.dictLabel"
            :value="item.dictCode">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="种植方式" prop="plantingWay">
        <el-select v-model="queryParams.plantingWay" placeholder="请选择种植方式">
          <el-option
            v-for="item in plantingWay"
            :key="item.dictCode"
            :label="item.dictLabel"
            :value="item.dictCode">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="种植年度" prop="plantingYear">
        <el-input
          v-model="queryParams.plantingYear"
          placeholder="请输入种植年度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['source:crop:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['source:crop:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['source:crop:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['source:crop:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="农作物图片" align="center" prop="cropImg">
        <template slot-scope="scope">
          <el-avatar shape="square" :size="100" :fit="'cover'" :src="scope.row.cropImg"></el-avatar>
        </template>
      </el-table-column>
      <el-table-column label="农作物名称" align="center" prop="cropName">
        <template slot-scope="scope">
          <router-link :to="'/source/crop-record/index/' + scope.row.cropId" class="link-type">
            <span>{{scope.row.cropName}}</span>
          </router-link>
        </template>
      </el-table-column>
      <el-table-column label="农作物类型" align="center" prop="cropTypeName" >
      </el-table-column>

      <el-table-column label="种植开始时间" align="center" prop="plantCreated" />
      <el-table-column label="生长周期" align="center" prop="growthCycle" />
      <el-table-column label="种植结束时间" align="center" prop="plantEndTime" />
      <el-table-column label="种植范围/亩" align="center" prop="plantRange" />
      <el-table-column label="每亩/斤" align="center" prop="plantAxe" />
      <el-table-column label="预计收货数量" align="center" prop="delivery" />
      <el-table-column label="实际收货数量" align="center" prop="shidelivery" />
      <el-table-column label="详细地址" align="center" prop="address" width="130px;" />
      <el-table-column label="质检状态" align="center" prop="recordStatus" >
        <template scope="scope">
          <el-tag type="warning"  size="mini" plain v-if="scope.row.recordStatus==null">未送检</el-tag>
          <el-tag type="info" size="mini" plain  v-if="scope.row.recordStatus==0">质检已通过</el-tag>
          <el-tag type="danger"  size="mini" plain v-if="scope.row.recordStatus==1">质检未通过</el-tag>
          <el-tag type="success" size="mini"  plain  v-if="scope.row.recordStatus==2">质检审核中</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="种植状态" align="center" prop="status"  width="130px;">
        <template scope="scope">
          <el-tag type="success" size="mini" plain  v-if="scope.row.status==0">已采摘</el-tag>
          <el-tag type="warning"  size="mini" plain v-if="scope.row.status==1">已成熟待采摘</el-tag>
          <el-tag type="danger" size="mini"  plain  v-if="scope.row.status==2">未成熟</el-tag>

        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="medium" type="text" v-if="scope.row.recordStatus==null && scope.row.status==0"  @click="handlegetzhi(scope.row)">质检</el-button>
          <el-button size="medium" type="text" v-if="scope.row.recordStatus==0">质检已通过</el-button>
          <el-button size="medium" type="text" v-if="scope.row.recordStatus==1 && scope.row.status==0"  @click="handlegetzhi(scope.row)">质检</el-button>
          <el-button size="medium" type="text" v-if="scope.row.recordStatus==2">质检审核中</el-button>
          <el-button
            size="medium"
            type="text"
            v-if="scope.row.status==1"
            @click="handleGetupdatestatus(scope.row)"
          >采摘</el-button>
          <el-button
             size="medium"
            type="text"
            @click="handleGetByiIds(scope.row)"
          >入库</el-button>
          <el-button
            size="medium"
            type="text"
            @click="handleGetByiId(scope.row.cropId)"
          >查看详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <el-dialog title="查看农作物详情" :visible.sync="dialogTableVisibles">
      <el-table :data="getByIds">
        <el-table-column  property="cropTypeName" label="种植方式"   width="150" />
        <el-table-column  property="plantingYear" label="种植年度" width="150" />
        <el-table-column  property="isBag" label="是否套袋"  width="150">
          <template scope="scope">
            <span v-if="scope.row.isBag==='0'">是</span>
            <span v-if="scope.row.isBag==='1'">否</span>
          </template>
        </el-table-column>
        <el-table-column  property="wateringPeriod" label="灌溉周期" width="150"  />
        <el-table-column  property="seedPeriod" label="育苗周期"  width="150"  />
        <el-table-column  property="manurePeriod" label="施肥周期" width="150"  />
        <el-table-column  property="weedingPeriod"  label="除草周期"   width="150" />
      </el-table>
    </el-dialog>

    <!-- 添加或修改农作物信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
      <el-form ref="form" :inline="true" :model="form" label-width="100px">
        <el-row>
          <el-col span="12">
            <el-form-item label="农作物名称" prop="cropName">
              <el-input v-model="form.cropName" placeholder="请输入农作物名称" />
            </el-form-item>
          </el-col>
          <el-col span="12">
            <el-form-item label="农作物类型" prop="plantingWay">
              <el-select v-model="form.cropType" placeholder="请输入种植方式">
                <el-option
                  v-for="item in cropType"
                  :key="item.dictCode"
                  :label="item.dictLabel"
                  :value="item.dictCode">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col span="12">
            <el-form-item label="种植方式" prop="plantingWay">
              <el-select v-model="form.plantingWay" placeholder="请输入种植方式">
                <el-option
                  v-for="item in plantingWay"
                  :key="item.dictCode"
                  :label="item.dictLabel"
                  :value="item.dictCode">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col span="12">
            <el-form-item label="肥料类型" prop="plantingWay">
              <el-select v-model="form.manureType" placeholder="请输入种植方式">
                <el-option
                  v-for="item in manureType"
                  :key="item.dictCode"
                  :label="item.dictLabel"
                  :value="item.dictCode">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col span="12">
            <el-form-item label="种植年度" prop="plantingYear">
              <el-input v-model="form.plantingYear" placeholder="请选择种植年度" />
            </el-form-item>
          </el-col>
          <el-col span="12">
            <el-form-item label="是否套袋" prop="isBag">
              <el-select v-model="form.isBag" placeholder="请选择是否套袋">
                <el-option :key="0" label="是" value="0"></el-option>
                <el-option :key="1" label="否" value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col span="12">
            <el-form-item label="灌溉周期" prop="wateringPeriod">
              <el-input v-model="form.wateringPeriod" placeholder="请输入灌溉周期" />
            </el-form-item>
          </el-col>
          <el-col span="12">
            <el-form-item label="育苗周期" prop="seedPeriod">
              <el-input v-model="form.seedPeriod" placeholder="请输入育苗周期" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col span="12">
            <div v-if="form.cropId!==null">
              <el-form-item label="施肥周期" prop="manurePeriod"  >
                <el-input v-model="form.manurePeriod" placeholder="请输入施肥周期" />
              </el-form-item>
            </div>

          </el-col>
          <el-col span="12">
            <el-form-item label="除草周期" prop="weedingPeriod">
              <el-input v-model="form.weedingPeriod" placeholder="请输入除草周期" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col span="12">
            <el-form-item label="种植开始时间" prop="manurePeriod">
              <el-date-picker
                v-model="form.plantCreated"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                format="yyyy-MM-dd HH:mm:ss"
                placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col span="12">
            <el-form-item label="生长周期" prop="weedingPeriod">
              <el-input v-model="form.growthCycle" placeholder="请输入除草周期" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col span="12">
            <el-form-item label="每亩/斤" prop="manurePeriod">
              <el-input v-model="form.plantAxe" placeholder="请输入施肥周期" />
            </el-form-item>
          </el-col>
          <el-col span="12">
            <el-form-item label="种植范围/亩" prop="weedingPeriod">
              <el-input v-model="form.plantRange" placeholder="请输入除草周期" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col span="12">
            <el-form-item label="详细地址" prop="address">
              <el-cascader
                placeholder="请选择详细地址"
                v-model="address"
                :options="addressData"
                :props="addressProps"
                @change="handleChange">
              </el-cascader>
            </el-form-item>
          </el-col>
          <el-col span="12">
            <el-form-item label="归属部门" prop="deptId">
              <div style="width: 200px;">
                <treeselect v-model="form.deptId" :options="deptOptions" :show-count="true" placeholder="请选择归属部门" />
              </div>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col span="12">
            <el-form-item label="农作物图片" prop="cropImg">
              <el-upload
                class="avatar-uploader"
                :action=upload.url
                :headers = upload.headers
                :show-file-list="false"
                :on-success="handleAvatarSuccess">
                <img v-if="imageUrl" :src="imageUrl" class="avatar">
                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
              </el-upload>
            </el-form-item>
          </el-col>
          <el-col span="12">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" placeholder="请输入备注" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col span="12">
            <el-form-item label="实际收货数量" prop="shidelivery" v-if="isAdding">
              <el-input v-model="form.shidelivery" placeholder="请输入实际收货数量" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
     <!--采摘-->
    <el-dialog title="采摘收货" :visible.sync="dialogFormVisible">
      <el-form :model="formcai">
        <el-form-item label="采摘名称" :label-width="formLabelWidth">
          <el-input v-model="formcai.cropName" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="收货数量/斤" :label-width="formLabelWidth">
          <el-input v-model="formcai.shidelivery" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="updatebystattus()">确 定</el-button>
      </div>
    </el-dialog>
    <!--入库-->
    <el-dialog :title="入库" :visible.sync="opens" width="500px" append-to-body>
      <el-form ref="forms" :model="forms" label-width="80px"   :rules="rules">
        <el-form-item label="货物id" prop="goodsId" >
          <el-input v-model="forms.goodsId" placeholder="请输入货物id"  disabled/>
        </el-form-item>
        <el-form-item label="货物数量" prop="goodsNum" >
          <el-input v-model="forms.goodsNum" placeholder="请输入货物数量" />
        </el-form-item>
        <el-form-item label="物流公司" prop="logisticsCompany">
          <el-select v-model="form.logisticsCompany" filterable placeholder="请输入物流公司">
            <el-option
              v-for="item in plantingWayss"
              :key="item.deptId"
              :label="item.deptName"
              :value="item.deptId">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="选择仓库" prop="logisticsCompany">
          <el-select v-model="form.storeId" filterable placeholder="请输入选择仓库">
            <el-option
              v-for="item in getStore"
              :key="item.store_id"
              :label="item.store_name"
              :value="item.store_id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="选择司机" prop="logisticsCompany">
          <el-select v-model="form.uid" filterable placeholder="请输入选择司机">
            <el-option
              v-for="item in deptUserss"
              :key="item.userId"
              :label="item.nickName"
              :value="item.userId">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForms">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!--质检-->
    <el-dialog :title="质检" :visible.sync="openss" width="500px" append-to-body>
      <el-form ref="forms" :model="formss" label-width="80px"  >
        <el-form-item label="货物id" prop="goodsId" >
          <el-input v-model="formss.goodsId" placeholder="请输入货物id"  disabled/>
        </el-form-item>
        <el-form-item label="货物名称" prop="goodsNum" >
          <el-input v-model="formss.cropName" placeholder="请输入货物名称" />
        </el-form-item>
        <el-form-item label="选择质检员" prop="logisticsCompany">
          <el-select v-model="formss.inspectors"  filterable placeholder="请输入质检员">
            <el-option
              v-for="item in listRecorda"
              :key="item.userId"
              :label="item.nickName"
              :value="item.userId">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormss">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listInfo, getInfo, delInfo, addInfo, updateInfo,listInfos ,updatestatus,addwuliu} from "@/api/source/crop/info";
import { selectByDictType } from "@/api/system/dict/data"
import { selectAddress } from "@/api/source/city"
import { deptTreeSelect } from "@/api/system/user";
import { getToken } from "@/utils/auth";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import {addRecord, getRecord, listRecord, listRecords} from "@/api/source/check/check";
import { getStoreList } from "@/api/source/store/in/store";
import {addLogistics, deptUser} from "@/api/source/logistics/logistics";



export default {
  name: "Info",
  components: {Treeselect},
  data() {
     var numberRule=(rules,value,callback)=>{
       const kecun =this.kucun;
       console.log(kecun)
       console.log(value)
       if(Number(value)<=Number(kecun)){
         if(Number.isInteger(Number(value))&& Number(value)>0){
           callback()
         }else{
           callback(new Error('请输入大于零的正整数'))
         }
       }else{
         callback(new Error('输入的货物数量不得大于库存量'))
       }
     }
    return {
      openss:false,
      formss:{},
      isAdding:false,
      formcai:{},
      formLabelWidth:'120px',
      dialogFormVisible:false,
       zhijianids:'',
      //上传图片地址
      upload: {
        headers: { Authorization: "Bearer " + getToken()},
        url: process.env.VUE_APP_BASE_API + "/source/crop/file/upload"
      },
      //图片
      imageUrl:null,
      //地区结构重定义
      addressProps:{
        value:"cityId",
        label:"cityName"
      },
      // 部门树选项
      deptOptions: undefined,
      //地区选择后的数据
      address:[],
      //农作物类型列表
      cropType:[],
      //肥料类型列表
      manureType:[],
      plantingWayss:[],
      //种植类型
      plantingWay:[],
      //地区数据
      addressData:[],
      // 遮罩层
      loading: true,
      opens:false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      forms:{},
      // 总条数
      total: 0,
      // 农作物信息表格数据
      infoList: [],
      zhijianbyids:[],
      kucun:'',
      deptUserss:[],
      getByIds:[],
      listRecorda:[],
      // 弹出层标题
      title: "",
      dialogTableVisibles:false,
      // 是否显示弹出层
      open: false,
      getStore:[],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        cropName: null,
        cropType: null,
        plantingWay: null,
        plantingYear: null,
      },
      // 表单参数
      form: {},
      zhijian:{},
      // 表单校验
      rules: {
        goodsNum: [
          { required:true ,message: '请输入货物数量' ,trigger: 'blur'},
           {validator: numberRule ,trigger: 'blur'}
       ]
      }
    };
  },

  methods: {

    handleGetupdatestatus(row){
      this.formcai.cropName=row.cropName;
      this.formcai.cropId=row.cropId;
      this.dialogFormVisible=true;
    },
    updatebystattus(){
      updatestatus(this.formcai).then(res=>{
        this.$message.success("采摘成功");
        this.dialogFormVisible=false;
        this.getList();
      })
    },
    submitForms(){
      addwuliu(this.forms).then(response => {
        this.$modal.msgSuccess("已提交入库申请");
        this.opens = false;
        this.getList()
      });
    },
    handlegetzhi(row){
        this.formss.goodsId=row.cropId;
        this.formss.cropName=row.cropName;
        this.formss.goodsType='0'
       this.openss=true;
    },
    submitFormss(){
      addRecord(this.formss).then(res=>{
        this.$message.success(res.msg);
        this.openss=false;
        this.getList()
      })
    },
    handleGetByiIds(row){
      if(row.recordStatus==0){
        this.kucun=row.shidelivery
        console.log(this.kucun);
        this.forms.goodsId=row.cropId;
        this.opens = true;
        this.title = "添加物流记录";
      }else{
        alert("质检未通过 等待质检通过后再入库")
      }

    },
    handleGetByiId(cropId){
      const cropIds = cropId
      getInfo(cropIds).then(response => {
        this.getByIds.push(response.data);
        console.log(this.getByIds);
        this.imageUrl=response.data.cropImg;
        this.address.push(response.data.provinceId,response.data.cityId,response.data.countyId);
        console.log(this.address);
        this.dialogTableVisibles=true;
      });

    },
    /** 查询部门下拉树结构 */
    getDeptTree() {
      deptTreeSelect().then(response => {
        this.deptOptions = response.data;
      });
    },
    /** 查询部门下拉树结构 */
    getDeptTreess() {
      listInfos().then(response => {
        this.plantingWayss = response.data;
      });
    },
    //图片
    handleAvatarSuccess(res,file){
      this.imageUrl = file.response.msg;
      this.form.cropImg=file.response.msg;
      console.log(file);
    },
    //选择地区
    handleChange(value) {
      this.form.provinceId=value[0];
      this.form.cityId=value[1];
      this.form.countyId=value[2];
    },
    //获取地区数据
    getAddressData(){
      selectAddress().then(res=>{
        this.addressData=res.rows;
      })
    },
    //获取司机
    deptUsers(){
      deptUser().then(res=>{
        this.deptUserss=res.data;
      })
    },   //获取司机
    listRecord(){
      listRecords().then(res=>{
        this.listRecorda=res.data;
      })
    },
    //获取仓库
    getStoreLists(){
      getStoreList().then(res=>{
        this.getStore=res.rows;
      })
    },
    //获取农作物类型
    getCropType(dictType){
      selectByDictType(dictType).then(res=>{
        this.cropType = res.rows;
      })
    },
    //获取肥料类型
    getManureType(dictType){
      selectByDictType(dictType).then(res=>{
        this.manureType = res.rows;
      })
    },
    //获取种植方式
    getPlantingWay(dictType){
      selectByDictType(dictType).then(res=>{
        this.plantingWay = res.rows;
      })
    },
    /** 查询农作物信息列表 */
    getList() {
      this.loading = true;
      listInfo(this.queryParams).then(response => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.opens = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        cropId: null,
        cropName: null,
        cropType: null,
        manureType: null,
        plantingWay: null,
        plantingYear: null,
        isBag: null,
        wateringPeriod: null,
        seedPeriod: null,
        manurePeriod: null,
        weedingPeriod: null,
        address: null,
        cropImg: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams={
        pageNum: 1,
        pageSize: 10,
        cropName: null,
        cropType: null,
        plantingWay: null,
        plantingYear: null
      };
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.cropId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.address=[];
      this.imageUrl=null;
      this.open = true;
      this.title = "添加农作物信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.address=[];
      this.isAdding=true
      this.imageUrl=null;
      this.reset();
      const cropId = row.cropId || this.ids
      getInfo(cropId).then(response => {
        this.form = response.data;
        this.imageUrl=response.data.cropImg;
        this.address.push(response.data.provinceId,response.data.cityId,response.data.countyId);
        console.log(this.address);
        this.open = true;
        this.title = "修改农作物信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.cropId != null) {
            updateInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const cropIds = row.cropId || this.ids;
      this.$modal.confirm('是否确认删除农作物信息编号为"' + cropIds + '"的数据项？').then(function() {
        return delInfo(cropIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/info/export', {
        ...this.queryParams
      }, `info_${new Date().getTime()}.xlsx`)
    }
  },
  created() {
    this.deptUsers();
    this.listRecord();
    this.getStoreLists();
    this.getDeptTreess();
    this.getDeptTree();
    this.getList();
    //获取农作物类型
    this.getCropType("src_crop_type");
    //获取肥料类型
    this.getManureType("src_manure_type");
    //获取种植方式
    this.getPlantingWay("src_planting_way");
    //获取地区数据
    this.getAddressData();
  },
};
</script>
<style>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>
